<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script src="https://unpkg.com/immer@6.0.3/dist/immer.umd.production.min.js"></script>
<script>
  immer.enableMapSet()

  const useMap = new WeakMap([
    [document.head, 2]
  ])

  console.log(eval('useMap.get(document.head)'));

  function createRemoveFunc(path) {
    let func = `draft`;
    const replace = `.splice(${path.pop()}, 1)`
      // .splice(index, 0, dataTransfer)
    while (path.length) {
      const index = path.shift()

      func += `[${ +index }].children`;
    }
    func += replace;
    return new Function('draft', func)
  }

  const data = [{key: 1, children: [{ key: 2, children: []}, { key: 4, children: []}]}]
  const func = createRemoveFunc([0, 0])
  func(data)
  console.log(data);
</script>
</body>
</html>
